package cn.gailvlun.gll.presentation.emotion.util

import android.app.Activity
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.annotation.FloatRange
import android.support.v4.content.ContextCompat
import android.widget.FrameLayout
import cn.gailvlun.gll.R
import cn.gailvlun.gll.widget.NavigationBarView


@Deprecated("建议使用BarBuilder")
object BarUtil {

    fun adaptHeaderBgWithNotificationIcon(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptHeaderBgWithNotificationIcon(activity, nbv, flFakeStatusBar, R.drawable.nbv_emotion_notification_default)
    }

    fun adaptListBgWithNotificationIcon(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptListBgWithNotificationIcon(activity, nbv, flFakeStatusBar, R.drawable.nbv_emotion_notification_scroll)
    }

    fun adaptHeaderBg(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptHeaderBgWithNotificationIcon(activity, nbv, flFakeStatusBar, null)
    }

    fun adaptListBg(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptListBgWithNotificationIcon(activity, nbv, flFakeStatusBar, null)
    }


    private fun adaptHeaderBgWithNotificationIcon(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout,
                                                  @DrawableRes nbvMenuIcon: Int?) {
        setBar(activity, nbv, flFakeStatusBar,
                1f,
                R.color.white,
                R.drawable.nbv_emotion_back_default,
                nbvMenuIcon,
                R.color.transparent)

    }


    private fun adaptListBgWithNotificationIcon(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout,
                                                @DrawableRes nbvMenuIcon: Int?) {
        setBar(activity, nbv, flFakeStatusBar,
                1f,
                R.color.g22,
                R.drawable.nbv_emotion_back_scroll,
                nbvMenuIcon,
                R.color.white)
    }

    
    fun adaptHeaderBg2(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptHeaderBgWithNotificationIcon2(activity, nbv, flFakeStatusBar, null)
    }


    fun adaptListBg2(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout) {
        adaptListBgWithNotificationIcon2(activity, nbv, flFakeStatusBar, null)
    }


    private fun adaptHeaderBgWithNotificationIcon2(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout,
                                                   @DrawableRes nbvMenuIcon: Int?) {
        setBar(activity, nbv, flFakeStatusBar,
                1f,
                R.color.g22,
                R.drawable.nbv_emotion_back_scroll,
                nbvMenuIcon,
                R.color.transparent)

    }

    private fun adaptListBgWithNotificationIcon2(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout,
                                                 @DrawableRes nbvMenuIcon: Int?) {
        setBar(activity, nbv, flFakeStatusBar,
                1f,
                R.color.g22,
                R.drawable.nbv_emotion_back_scroll,
                nbvMenuIcon,
                R.color.white)
    }

    


    private fun setBar(activity: Activity, nbv: NavigationBarView, flFakeStatusBar: FrameLayout,
                       @FloatRange(from = 0.0, to = 1.0) nbvAlpha: Float,
                       @ColorRes nbvTitleColor: Int,
                       @DrawableRes nbvBackIcon: Int,
                       @DrawableRes nbvMenuIcon: Int?,
                       @ColorRes fakeStatusBarBgColor: Int) {
        nbv.alpha = nbvAlpha
        nbv.setTitleColor(nbvTitleColor)
        nbv.setBackIcon(nbvBackIcon)
        if (nbvMenuIcon != null) {
            nbv.setMenuIcon(nbvMenuIcon)
        }
        flFakeStatusBar.setBackgroundColor(ContextCompat.getColor(activity, fakeStatusBarBgColor))

    }
}